package com.sali.rule;


import com.sali.utils.SnowflakeIdWorkerUtil;
import org.apache.commons.lang3.StringUtils;


public class FileIdRule implements Rule {
    private SnowflakeIdWorkerUtil instance = SnowflakeIdWorkerUtil.getInstance();
    private static Rule rule;

    static {
        rule = new FileIdRule();
    }

    @Override
    public Object invoke(Object value) {
        if (value == null || StringUtils.isEmpty((CharSequence) value)) {
            return null;
        } else {
            long nextId = instance.nextId();
            String reverse = StringUtils.reverse(String.valueOf(nextId));
            return reverse;
        }
    }

    /**
     * 获取实例方法
     *
     * @return
     */
    public static Rule getInstance() {
        return rule;
    }
}
